﻿#include "bricks.h"
#include <SDL3/SDL.h>
#include<iostream>
bricks::bricks(SDL_Renderer* renderer):m_renderer(renderer)
{
    //��ʼ��ש���λ�ã�ͬʱ����ש��
    int row, col;
    for (row = 0; row < BRICK_ROW; row++) {
        for (col = 0; col < BRICK_COL; col++) {
            brickRectsArry[row][col].x = row * BRICK_WIDTH;
            brickRectsArry[row][col].y = col * BRICK_HEIGHT;
            //���Ʒ���
            SDL_SetRenderDrawColor(m_renderer, 0,255, 0, SDL_ALPHA_OPAQUE);  /* red, full alpha */

            rects.x = row * BRICK_WIDTH;
            rects.y = col * BRICK_HEIGHT;
            rects.h = BRICK_HEIGHT;
            rects.w = BRICK_WIDTH;
            SDL_RenderRect(m_renderer, &rects);
        }
    }
    //����ש��

   
}



int bricks::getBrickRowNum()
{
    return BRICK_ROW;
}

int bricks::getBrickColNum()
{
    return BRICK_COL;
}

bricks::~bricks()
{
}

void bricks::updateShow()
{

    int row, col;

    for (row = 0; row < BRICK_ROW; row++) {
        for (col = 0; col < BRICK_COL; col++) {
       
            if ((brickRectsArry[row][col].x == 0) && (brickRectsArry[row][col].y == 0)) {
                continue;
            }
            SDL_SetRenderDrawColor(m_renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);  /* red, full alpha */
            rects.x = brickRectsArry[row][col].x;
            rects.y = brickRectsArry[row][col].y;
            //std::cout<<"rects.x:"<<rects.x<<" rects.y:"<<rects.y<<std::endl;
            rects.h = BRICK_HEIGHT;
            rects.w = BRICK_WIDTH;
            SDL_RenderRect(m_renderer, &rects);
        }
    }

}

void bricks::deleteBrick(int row, int col)
{
    
        brickRectsArry[row][col].x = 0;
        brickRectsArry[row][col].y = 0;


}

brickRects& bricks::getBriksRectsArry(int col, int row)
{
    if (row >= 0 && row < BRICK_ROW && col >= 0 && col < BRICK_COL) {
        return brickRectsArry[row][col];
    }
}
